package com.ruoyi.web.controller.function;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysRole;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.entity.GlPeople;
import com.ruoyi.system.service.GlPeopleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

import static com.ruoyi.common.utils.PageUtils.startPage;

/**
 * @author Y·C
 * @version 1.0.0
 * @ClassName GlPeopleController.java
 * @Description TODO
 * @createTime 2023年11月12日 11:46:00
 */
@Api(tags = "隔离人员管理接口")
@RestController
@RequestMapping("/glPeople")
public class GlPeopleController extends BaseController {

    @Autowired
    private GlPeopleService glPeopleService;


    @Anonymous
    @ApiOperation(value = "获取隔离人员列表")
    @GetMapping("/getGlPeopleInfoList")
    public TableDataInfo getGlPeopleInfoList(Integer pageNum,
                                             Integer pageSize,
                                             String userName,
                                             String phoneNumber,
                                             String idNumber,
                                             String address,
                                             String startTime,
                                             String endTime) {
        startPage();  // 此方法配合前端完成自动分页
        List<GlPeople> glPeopleList =glPeopleService.getGlPeopleInfoList(userName, phoneNumber, idNumber, address, startTime, endTime);
        return getDataTable(glPeopleList);
    }

    @Anonymous
    @ApiOperation(value = "根据id获取隔离人员信息")
    @GetMapping("/getGlPeopleInfoById/{id}")
    public AjaxResult getGlPeopleInfoById(@PathVariable("id") Long id) {
        return AjaxResult.success(glPeopleService.getById(id));
    }

    @Anonymous
    @ApiOperation(value = "删除隔离人员信息")
    @DeleteMapping("/deleteGlPeopleInfoById")
    public AjaxResult deleteGlPeopleInfoById(@RequestBody List<Long> ids) {
        return AjaxResult.success(glPeopleService.removeByIds(ids));
    }

    @Anonymous
    @ApiOperation(value = "添加隔离人员信息")
    @PostMapping("/addGlPeopleInfo")
    public AjaxResult addGlPeopleInfo(@RequestBody GlPeople glPeople) {
        return AjaxResult.success(glPeopleService.save(glPeople));
    }
    @Anonymous
    @ApiOperation(value = "修改隔离人员信息")
    @PutMapping("/updateGlPeopleInfo")
    public AjaxResult updateGlPeopleInfo(@RequestBody GlPeople glPeople) {
        return AjaxResult.success(glPeopleService.updateById(glPeople));
    }

    // @Log(title = "用户管理", businessType = BusinessType.EXPORT)
    @Anonymous
    @ApiOperation(value = "导出隔离人员信息")
    @RequestMapping("/export")
    public void export(HttpServletResponse response, GlPeople glPeople) {
        List<GlPeople> glPeopleList =glPeopleService.getGlPeopleInfoList(glPeople.getUserName(),
                glPeople.getPhoneNumber(), glPeople.getIdNumber(), glPeople.getAddress(), null, null);
        ExcelUtil<GlPeople> util = new ExcelUtil<GlPeople>(GlPeople.class);
        util.exportExcel(response,glPeopleList, "隔离人员数据");
    }

    /**
     * 查询隔离人员列表姓名和id
     */
    @ApiOperation(value = "查询隔离人员列表姓名和id")
    @GetMapping("/getGlPeopleNameAndId")
    @Anonymous
    public AjaxResult getGlPeopleNameAndId() {
        return AjaxResult.success(glPeopleService.getGlPeopleNameAndId());
    }

}
